package presentacion;

import integracion.DatabaseManager;
import integracion.ActividadDAO;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import share.Actividad;

public class IngresarActividad extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
{
	static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		doAll(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		doAll(request, response);
	}

	private void doAll(HttpServletRequest request, HttpServletResponse response) throws IOException
	{
		System.out.println(request.getParameter("opciones"));


		if(request.getParameter("accion").equals("Aceptar"))
		{
			Actividad actividad = new Actividad();
			actividad.setNombre(request.getParameter("nombre"));
			actividad.setDuracion(Integer.parseInt(request.getParameter("duracion")));
			actividad.setComponente(request.getParameter("opciones"));


			try
			{
				ActividadDAO dao = new ActividadDAO(DatabaseManager.getConnection());
				dao.insert(actividad);

			} catch (SQLException e)
			{
				e.printStackTrace();
			}
		}

		response.sendRedirect("index.jsp?page=GestionarActividades/GestionarActividades");
	}
}
